﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMTC.Model.Domain;
using System.Data.Common;
using IMPlant.Core.Data.Unity;
using System.Data;
using SMTC.Model.Model;

namespace SMTC.Dao.Line
{
    public class LineQueryDao : BaseDao
    {
        /// <summary>
        /// 获取line列表
        /// </summary>
        private const string SQL_SELECT_LINE = @"SELECT LineID,
	                                                   LineName,
	                                                   LineTargetTime,
	                                                   BUID,
	                                                   ModifyPerson,
	                                                   ModifyDateTime,
	                                                   LineCapacity 
                                                FROM dbo.SMT_Line
                                                WHERE LineName LIKE @LineName
                                                AND (LineTargetTime = @LineTargetTime or @LineTargetTime = 0)
                                                AND ModifyPerson LIKE @ModifyPerson
                                                AND (LineCapacity = @LineCapacity or @LineCapacity = 0)
                                                AND ModifyDateTime BETWEEN @startTime AND @endTime order by LineName";
        /// <summary>
        /// 获取生产线贴片机列表
        /// </summary>
        private const string SQL_SELECT_LINE_PRODUCTUNIT = @"SELECT PUID,
	                                                                   PUType,
	                                                                   PUCapacity,
	                                                                   Para,
	                                                                   ModifyPerson,
	                                                                   ModifyDateTime,
	                                                                   LineID FROM dbo.SMT_ProductionUnit
                                                                WHERE LineID = @LineID";
        /// <summary>
        /// 获取单个生产线实体
        /// </summary>
        private const string SQL_SELECT_LINE_SINGLE = @"SELECT LineID,
	                                                           LineName,
	                                                           LineTargetTime,
	                                                           BUID,
	                                                           ModifyPerson,
	                                                           ModifyDateTime,
	                                                           LineCapacity FROM dbo.SMT_Line
                                                        WHERE LineID = @LineID";
        /// <summary>
        /// 获取lineList
        /// </summary>
        /// <param name="LineName"></param>
        /// <param name="LineTargetTime"></param>
        /// <param name="ModifyPerson"></param>
        /// <param name="LineCapacity"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List<SMT_LineModel> GetLineList(string LineName, int LineTargetTime, string ModifyPerson, int LineCapacity, DateTime startTime, DateTime endTime)
        {
            DbParameter[] parameters = 
            {
                DBparameterBuild.Build("@LineName",LineName)
               ,DBparameterBuild.Build("@LineTargetTime",LineTargetTime)
               ,DBparameterBuild.Build("@ModifyPerson",ModifyPerson)
               ,DBparameterBuild.Build("@LineCapacity",LineCapacity)
               ,DBparameterBuild.Build("@startTime",startTime)
               ,DBparameterBuild.Build("@endTime",endTime)
            };

            return DBTemplete.ExcuteGetList<SMT_LineModel>(CommandType.Text, SQL_SELECT_LINE, parameters);
        }

        /// <summary>
        /// 获取lineList供选择生成线时使用
        /// </summary>
        /// <param name="LineName"></param>
        /// <param name="LineTargetTime"></param>
        /// <param name="ModifyPerson"></param>
        /// <param name="LineCapacity"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List<SMT_LineModel> GetLineListForSelect(string LineName, int LineTargetTime, string ModifyPerson, int LineCapacity, DateTime startTime, DateTime endTime)
        {
            string str = SQL_SELECT_LINE + " and BUID is null ";
            DbParameter[] parameters = 
            {
                DBparameterBuild.Build("@LineName",LineName)
               ,DBparameterBuild.Build("@LineTargetTime",LineTargetTime)
               ,DBparameterBuild.Build("@ModifyPerson",ModifyPerson)
               ,DBparameterBuild.Build("@LineCapacity",LineCapacity)
               ,DBparameterBuild.Build("@startTime",startTime)
               ,DBparameterBuild.Build("@endTime",endTime)
            };

            return DBTemplete.ExcuteGetList<SMT_LineModel>(CommandType.Text, str, parameters);
        }
        /// <summary>
        /// 获取生产线实体
        /// </summary>
        /// <param name="LineID"></param>
        /// <returns></returns>
        public SMT_LineModel getLineModel(string LineID)
        {
             DbParameter[] parameters = 
            {
                DBparameterBuild.Build("@LineID",LineID)
            };

            return DBTemplete.ExcuteGetObject<SMT_LineModel>(CommandType.Text,SQL_SELECT_LINE_SINGLE,parameters);
        }
        /// <summary>
        /// 获取生产线的贴片机列表
        /// </summary>
        /// <param name="LineID"></param>
        /// <returns></returns>
        public List<SMT_ProductionUnitModel> GetLineProductUnitList(string LineID)
        {
            DbParameter[] parameters = 
            {
                DBparameterBuild.Build("@LineID",LineID)
            };

            return DBTemplete.ExcuteGetList<SMT_ProductionUnitModel>(CommandType.Text, SQL_SELECT_LINE_PRODUCTUNIT, parameters);
        }

        
    }
}
